<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>中策</title>
</head>
<body>
    <h1>中策新闻</h1>
    <table>
        <tr>
            <td>新闻标题</td>
            <td>日期</td>
        </tr>
        {% for data in datas %}
        <tr>
            <td>{{data.title}}</td>
            <td>{{data.date}}</td>
        </tr>
        {% endfor %}
    </table>
    <button id="pre_page_button">上一页</button>
    <button id="next_page_button">下一页</button>
</body>

<script>
    document.getElementById("pre_page_button").onclick = function () {
        let result = window.location.href.slice(-2)
        result = result.replaceAll("/","")
        if(parseInt(result) == 1){
            document.getElementById("pre_page_button").innerText="已经是第一页了！"
        }else{
            window.location.href="http://127.0.0.1:5000/page/"+(parseInt(result)-1)
        }
        console.log(result)
    };

    document.getElementById("next_page_button").onclick = function () {
        let result = window.location.href.slice(-2)
        result = result.replaceAll("/","")
        window.location.href="http://127.0.0.1:5000/page/"+(parseInt(result)+1)
    };
</script>
</html>